package com.xiaoshuidi.cloud.module.rooms.controller.admin.grounding;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.grounding.vo.GroundingNumVo;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.grounding.vo.GroundingVo;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.iot.vo.DeviceReaVo;
import com.xiaoshuidi.cloud.module.rooms.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.rooms.pojo.RoomHouse;
import com.xiaoshuidi.cloud.module.rooms.repository.RoomHouseRepository;
import com.xiaoshuidi.cloud.module.rooms.service.RoomHouseService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @BelongsProject: lease-module-rooms
 * @BelongsPackage: com.xiaoshuidi.cloud.module.rooms.controller.admin.grounding
 * @Author: James
 * @CreateTime: 2023-11-03  10:03
 * @Description: TODO
 * @Version: 1.0
 */
@Slf4j
@Tag(name = "营销管理 - 房源发布")
@RestController
@RequestMapping(ApiConstants.NAME + "/groundingRoom")
@RequiredArgsConstructor
public class GroundingRoomController {

    @Autowired
    private RoomHouseRepository oomHouseRepository;

    /*
     * @description:房源上下架列表信息
     * @author: James
     * @date: 2023/11/8 11:32
     * @param: [groundingVo]
     * @return: com.xiaoshuidi.cloud.framework.common.pojo.CommonResult<com.xiaoshuidi.cloud.module.rooms.controller.admin.grounding.vo.GroundingNumVo>
     **/
    @GetMapping("/groundingRoomList")
    public CommonResult<GroundingNumVo> groundingRoomList(GroundingVo groundingVo) {
        IPage<GroundingVo> groundingRoomList = oomHouseRepository.getGroundingRoomList(groundingVo);
        GroundingNumVo groundingNumVo=new GroundingNumVo();
        groundingNumVo.setGroundingVoList(groundingRoomList);
        groundingNumVo.setUnGroundingNum(oomHouseRepository.getUnGroundingNum());
        groundingNumVo.setGroundingNum(oomHouseRepository.getGroundingNum());
        return CommonResult.success(groundingNumVo);
    }

    /*
     * @description:批量上下架
     * @author: James
     * @date: 2023/11/8 13:59
     * @param: [groundingVo]
     * @return: com.xiaoshuidi.cloud.framework.common.pojo.CommonResult
     **/
    @PostMapping("/setGroundingStatus")
    public CommonResult setGroundingStatus(@RequestBody GroundingVo groundingVo){
        List<Long> roomIds=groundingVo.getRoomIds();
        boolean grounding=groundingVo.isDoGrounding();
        log.info("上下架房源ids："+ JSONObject.toJSONString(roomIds));
        log.info("上下架操作："+ grounding);
        return oomHouseRepository.setGroundingStatus(roomIds,grounding);
    }

    /*
     * @description:一键发布
     * @author: James
     * @date: 2023/11/8 13:59
     * @param: [groundingVo]
     * @return: com.xiaoshuidi.cloud.framework.common.pojo.CommonResult
     **/
    @PostMapping("/setAllGrounding")
    public CommonResult setAllGrounding(){
        return oomHouseRepository.setAllGrounding();
    }

}
